import http from '@/api/api'

export default{
    namespaced: true,
    state:{
        Rlist:[],
        location:'定位中...',
        isShow:true,
    },
    mutations:{
        search(state, reslist ){
            state.Rlist = reslist
        },
        myPosition( state, location ){
            // console.log(location)
            state.location = location.substr(-8,8)
            // console.log( state.location )
        },
        showHot(state,value){
            state.isShow = value
        }
    },
    actions:{
        async search({commit}, word){
            let url = '/index-list.json'
            // 发起请求，得到整体的数据
            let res = await http.getRlist( url )
            // 匹配数据，得到符合条件的数据
            let data = res.data.data.poilist
            let l = word.length
            console.log(l)
            // console.log( data )
            let reslist = data.filter( p => p.name.substr(0,l) == word )
            console.log( reslist )
            
            commit('search',reslist)
        },
        myPosition({ commit }, location ){
            commit('myPosition', location )
        },
        showHot({commit},value){
            commit('showHot', value )
        }

    }
}